/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package restauranteaplicacion.Ingresos;

import Clases.Observador;
import javax.swing.JTextField;
import entidad.Producto;
import entidad.Proveedores;
import CapaNegocios.CNProducto;
import CapaNegocios.CNProveedor;
import CapaNegocios.CNOrdenEntrada;
import CapaNegocios.CNUnidadMedida;
import entidad.Lotes;
import entidad.Unidaddemedida;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import Clases.ComboBox;
import entidad.Ordenentrada;
import java.awt.Component;
import java.util.Observable;
import java.util.Observer;
import restauranteaplicacion.MDI;
import CapaNegocios.Conversor;
import java.util.Calendar;
/**
 *
 * @author Victor
 */
public final class IngresoCompras extends javax.swing.JInternalFrame  implements Observer{

    /**
     * Creates new form IngresoEmpleado
     */
    Observador obs;
    Observador obsPadre;
    DefaultTableModel modelo;
    List<Lotes> listaLotes;
    List<Lotes>listaEliminados;
    public IngresoCompras() {
        initComponents();
        obs=new Observador();
        obs.addObserver(this);
        modelo = (DefaultTableModel) Tabla.getModel();
        listaLotes = new ArrayList<>();
        obsPadre=null;
        ordenentrada1 = null;
        cargarUnidadMedida();
        listaEliminados=null;
        dateFechaFactura.setDate(Calendar.getInstance().getTime());
    }
    public void cargarUnidadMedida()
    {
        List<Unidaddemedida> lista = CNUnidadMedida.buscarTodos();
        cmbUnidadMedida.removeAllItems();
        
        for(Unidaddemedida lis : lista)
        {
            cmbUnidadMedida.addItem(new ComboBox(lis.getIdUnidadDeMedida(),lis.getNombre()));
        }
    }
    public void cargarUnidadMedidaConParametro(String parametro)
    {
        List<Unidaddemedida> lista = CNUnidadMedida.buscarTipo(parametro);
        cmbUnidadMedida.removeAllItems();
        
        for(Unidaddemedida lis : lista)
        {
            cmbUnidadMedida.addItem(new ComboBox(lis.getIdUnidadDeMedida(),lis.getNombre()));
        }
    }
    
    public  IngresoCompras(Observador ob)
    {
        initComponents();
        obsPadre=ob;
        obs=new Observador();
        obs.addObserver(this);
        modelo = (DefaultTableModel) Tabla.getModel();
        listaLotes = new ArrayList<>();
        ordenentrada1 = null;
        cargarUnidadMedida();
        listaEliminados=null;
        dateFechaFactura.setDate(Calendar.getInstance().getTime());
    }
    
    public  IngresoCompras(Observador ob, Ordenentrada orden)
    {
        initComponents();
        obsPadre=ob;
        obs=new Observador();
        obs.addObserver(this);
        modelo = (DefaultTableModel) Tabla.getModel();
        listaLotes = new ArrayList<>();
        cargarUnidadMedida();
        cargarOrde(orden);
        cargarLotes();
        txtNombre.setEnabled(false);
        listaEliminados= new ArrayList<>();
    }

    public void cargarOrde(Ordenentrada or)
    {
        ordenentrada1.setActivo(or.getActivo());
        ordenentrada1.setFecha(or.getFecha());
        ordenentrada1.setIdOrdenEntrada(or.getIdOrdenEntrada());
        ordenentrada1.setLotesCollection(or.getLotesCollection());
        ordenentrada1.setNoFactura(or.getNoFactura());
        ordenentrada1.setProveedoridProveedor(or.getProveedoridProveedor());
        ordenentrada1.setTotal(or.getTotal());
        dateFechaFactura.setDate(or.getFecha());
    }
    
    public void cargarLotes()
    {
        //modelo.addRow(new Object[]{producto.getNombre(),producto.getDescripcion(),cantidad,precioUnitario, precio});
        if(ordenentrada1.getLotesCollection()!=null)
        {
            ClearTable();
            for (Lotes lot : ordenentrada1.getLotesCollection()) {
                Producto producto = lot.getProductoidProducto();
                modelo.addRow(new Object[]{producto.getNombre(),producto.getDescripcion(),lot.getCantidad()
                        ,lot.getPrecioUnitario(), lot.getPrecioUnitario()*lot.getCantidad()});
                Float granTotal = Float.valueOf(labGranTotal.getText())+lot.getPrecioUnitario()*lot.getCantidad();
                labGranTotal.setText(granTotal.toString());
                listaLotes.add(lot);
            }
        }
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        ordenentrada1 = new entidad.Ordenentrada();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel20 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        txtFactura = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        dateFechaFactura = new com.toedter.calendar.JDateChooser();
        jLabel27 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();
        cmbNombreProveedor = new javax.swing.JComboBox();
        btnGuardar = new javax.swing.JButton();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jLabel28 = new javax.swing.JLabel();
        txtNombreProducto = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        cmbNombreProducto = new javax.swing.JComboBox();
        txtDescripcion = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        txtCantidad = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        txtPrecio = new javax.swing.JTextField();
        dateVencimiento = new com.toedter.calendar.JDateChooser();
        chbFechaVencimiento = new javax.swing.JCheckBox();
        jButton2 = new javax.swing.JButton();
        cmbUnidadMedida = new javax.swing.JComboBox();
        jLabel34 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        Tabla = new javax.swing.JTable();
        btnEliminar = new javax.swing.JButton();
        btnAgregar = new javax.swing.JButton();
        jLabel33 = new javax.swing.JLabel();
        labGranTotal = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setIconifiable(true);
        setTitle("Creacion de Compras");
        setAutoscrolls(true);
        setMaximumSize(new java.awt.Dimension(1045, 649));
        setMinimumSize(new java.awt.Dimension(1000, 520));
        setPreferredSize(new java.awt.Dimension(1045, 649));
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS));

        jPanel1.setBackground(new java.awt.Color(54, 149, 240));
        jPanel1.setMaximumSize(new java.awt.Dimension(2000, 50));
        jPanel1.setMinimumSize(new java.awt.Dimension(246, 50));
        jPanel1.setPreferredSize(new java.awt.Dimension(1000, 50));

        jLabel4.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Compras");
        jPanel1.add(jLabel4);

        getContentPane().add(jPanel1);

        jPanel4.setPreferredSize(new java.awt.Dimension(988, 430));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(494, 500));

        btnCancelar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/restauranteaplicacion/Ingresos/circle-x-3x.png"))); // NOI18N
        btnCancelar.setText("Salir");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setPreferredSize(new java.awt.Dimension(85, 53));
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel19.setText("INFORMACION PROVEEDOR");

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel20.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel20.setText("Proveedor");
        jLabel20.setBounds(10, 20, 60, 15);
        jLayeredPane1.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtNombre.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtNombre.setNextFocusableComponent(cmbNombreProveedor);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ordenentrada1, org.jdesktop.beansbinding.ELProperty.create("${proveedoridProveedor.nombre}"), txtNombre, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });
        txtNombre.setBounds(70, 10, 170, 30);
        jLayeredPane1.add(txtNombre, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setForeground(new java.awt.Color(102, 102, 255));
        jButton1.setText("+");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.setBounds(250, 10, 40, 30);
        jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel22.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel22.setText("Seleccionar Proveedor");
        jLabel22.setBounds(300, 20, 130, 15);
        jLayeredPane1.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel23.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel23.setText("Direccion");
        jLabel23.setBounds(590, 20, 60, 15);
        jLayeredPane1.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtDireccion.setEditable(false);
        txtDireccion.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ordenentrada1, org.jdesktop.beansbinding.ELProperty.create("${proveedoridProveedor.direccion}"), txtDireccion, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtDireccion.setBounds(650, 10, 170, 30);
        jLayeredPane1.add(txtDireccion, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtTelefono.setEditable(false);
        txtTelefono.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ordenentrada1, org.jdesktop.beansbinding.ELProperty.create("${proveedoridProveedor.telefono}"), txtTelefono, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtTelefono.setBounds(880, 10, 80, 30);
        jLayeredPane1.add(txtTelefono, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel24.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel24.setText("Telefono");
        jLabel24.setBounds(830, 20, 50, 15);
        jLayeredPane1.add(jLabel24, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel25.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel25.setText("Fecha");
        jLabel25.setBounds(340, 60, 50, 15);
        jLayeredPane1.add(jLabel25, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtFactura.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtFactura.setNextFocusableComponent(dateFechaFactura);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ordenentrada1, org.jdesktop.beansbinding.ELProperty.create("${noFactura}"), txtFactura, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtFactura.setBounds(70, 50, 220, 30);
        jLayeredPane1.add(txtFactura, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel26.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel26.setText("No Factura");
        jLabel26.setBounds(10, 60, 70, 15);
        jLayeredPane1.add(jLabel26, javax.swing.JLayeredPane.DEFAULT_LAYER);

        dateFechaFactura.setNextFocusableComponent(txtTotal);
        dateFechaFactura.setBounds(430, 50, 210, 30);
        jLayeredPane1.add(dateFechaFactura, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel27.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel27.setText("Total");
        jLabel27.setBounds(760, 60, 40, 15);
        jLayeredPane1.add(jLabel27, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtTotal.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtTotal.setNextFocusableComponent(txtNombreProducto);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ordenentrada1, org.jdesktop.beansbinding.ELProperty.create("${total}"), txtTotal, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtTotal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtTotalFocusGained(evt);
            }
        });
        txtTotal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTotalKeyTyped(evt);
            }
        });
        txtTotal.setBounds(810, 50, 150, 30);
        jLayeredPane1.add(txtTotal, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cmbNombreProveedor.setNextFocusableComponent(txtFactura);
        cmbNombreProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbNombreProveedorActionPerformed(evt);
            }
        });
        cmbNombreProveedor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cmbNombreProveedorKeyTyped(evt);
            }
        });
        cmbNombreProveedor.setBounds(430, 10, 150, 30);
        jLayeredPane1.add(cmbNombreProveedor, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnGuardar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/circle-check-3x.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setNextFocusableComponent(btnCancelar);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel28.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel28.setText("Nombre");
        jLabel28.setBounds(10, 20, 50, 15);
        jLayeredPane2.add(jLabel28, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtNombreProducto.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtNombreProducto.setNextFocusableComponent(cmbNombreProducto);
        txtNombreProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNombreProductoActionPerformed(evt);
            }
        });
        txtNombreProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreProductoKeyTyped(evt);
            }
        });
        txtNombreProducto.setBounds(60, 13, 170, 30);
        jLayeredPane2.add(txtNombreProducto, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel29.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel29.setText("Seleccione el Nombre");
        jLabel29.setBounds(290, 20, 130, 15);
        jLayeredPane2.add(jLabel29, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cmbNombreProducto.setNextFocusableComponent(txtCantidad);
        cmbNombreProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbNombreProductoActionPerformed(evt);
            }
        });
        cmbNombreProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cmbNombreProductoKeyTyped(evt);
            }
        });
        cmbNombreProducto.setBounds(420, 10, 180, 30);
        jLayeredPane2.add(cmbNombreProducto, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtDescripcion.setEditable(false);
        txtDescripcion.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtDescripcion.setBounds(680, 13, 290, 30);
        jLayeredPane2.add(txtDescripcion, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel30.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel30.setText("Descripcion");
        jLabel30.setBounds(610, 20, 80, 15);
        jLayeredPane2.add(jLabel30, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel31.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel31.setText("<html>Cantidad a comprar</html>");
        jLabel31.setBounds(10, 50, 70, 50);
        jLayeredPane2.add(jLabel31, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtCantidad.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtCantidad.setNextFocusableComponent(cmbUnidadMedida);
        txtCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCantidadKeyTyped(evt);
            }
        });
        txtCantidad.setBounds(80, 60, 110, 30);
        jLayeredPane2.add(txtCantidad, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel32.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel32.setText("<html>Unidad de Medida</html>");
        jLabel32.setBounds(200, 50, 70, 40);
        jLayeredPane2.add(jLabel32, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtPrecio.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtPrecio.setNextFocusableComponent(chbFechaVencimiento);
        txtPrecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtPrecioKeyTyped(evt);
            }
        });
        txtPrecio.setBounds(510, 60, 80, 30);
        jLayeredPane2.add(txtPrecio, javax.swing.JLayeredPane.DEFAULT_LAYER);

        dateVencimiento.setEnabled(false);
        dateVencimiento.setMinSelectableDate(Calendar.getInstance().getTime());
        dateVencimiento.setBounds(800, 60, 160, 30);
        jLayeredPane2.add(dateVencimiento, javax.swing.JLayeredPane.DEFAULT_LAYER);

        chbFechaVencimiento.setText("Fecha de Vencimiento");
        chbFechaVencimiento.setNextFocusableComponent(btnAgregar);
        chbFechaVencimiento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbFechaVencimientoActionPerformed(evt);
            }
        });
        chbFechaVencimiento.setBounds(610, 60, 150, 23);
        jLayeredPane2.add(chbFechaVencimiento, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton2.setBackground(new java.awt.Color(255, 255, 255));
        jButton2.setForeground(new java.awt.Color(102, 102, 255));
        jButton2.setText("+");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jButton2.setBounds(240, 10, 40, 30);
        jLayeredPane2.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cmbUnidadMedida.setNextFocusableComponent(txtPrecio);
        cmbUnidadMedida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbUnidadMedidaActionPerformed(evt);
            }
        });
        cmbUnidadMedida.setBounds(280, 60, 140, 30);
        jLayeredPane2.add(cmbUnidadMedida, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel34.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel34.setText("<html>SubTotal de la compral</html>");
        jLabel34.setBounds(440, 50, 70, 40);
        jLayeredPane2.add(jLabel34, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel21.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel21.setText("DETALLE DE LA COMPRA");

        jLayeredPane3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        Tabla.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        Tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre Producto", "Descripcion", "Unidad de Medida", "Cantidad", "Precio Unitario", "Precio Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Float.class, java.lang.Float.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        Tabla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(Tabla);
        Tabla.getColumnModel().getColumn(0).setResizable(false);
        Tabla.getColumnModel().getColumn(1).setResizable(false);
        Tabla.getColumnModel().getColumn(2).setResizable(false);
        Tabla.getColumnModel().getColumn(3).setResizable(false);
        Tabla.getColumnModel().getColumn(4).setResizable(false);
        Tabla.getColumnModel().getColumn(5).setResizable(false);

        jScrollPane1.setBounds(10, 20, 860, 140);
        jLayeredPane3.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/restauranteaplicacion/Ingresos/x-3x.png"))); // NOI18N
        btnEliminar.setText("Eliminar");
        btnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        btnEliminar.setBounds(880, 100, 80, 60);
        jLayeredPane3.add(btnEliminar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/plus-3x.png"))); // NOI18N
        btnAgregar.setText("Agregar");
        btnAgregar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAgregar.setNextFocusableComponent(txtNombreProducto);
        btnAgregar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });
        btnAgregar.setBounds(880, 20, 80, 60);
        jLayeredPane3.add(btnAgregar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel33.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel33.setText("Gran Total");

        labGranTotal.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        labGranTotal.setText("0.00");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLayeredPane3)
                    .addComponent(jLabel21)
                    .addComponent(jLabel19)
                    .addComponent(jLayeredPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 982, Short.MAX_VALUE)
                    .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 982, Short.MAX_VALUE))
                .addContainerGap(23, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel33)
                .addGap(28, 28, 28)
                .addComponent(labGranTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnGuardar)
                .addGap(46, 46, 46))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel33)
                        .addComponent(labGranTotal)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnGuardar))
                .addGap(49, 49, 49))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 1029, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 569, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel4);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        if(listaLotes.size()>=1)
        {
            if(Float.parseFloat(txtTotal.getText()) != Float.parseFloat(labGranTotal.getText()))
            {
                JOptionPane.showMessageDialog(this, "No Se ha guardado correctamente, porque la sumatoria de subtotales no es igual "
                        + "al total ingresado",
                                 "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(ordenentrada1!=null)
            {
                ordenentrada1.setFecha(dateFechaFactura.getDate());
                ordenentrada1.setLotesCollection(listaLotes);
                if(CNOrdenEntrada.modificar(ordenentrada1,listaEliminados)){
                    JOptionPane.showMessageDialog(this, "Se ha Modificado correctamente", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
                    obsPadre.actualizar();
                    this.setVisible(false);
                }
                else
                    JOptionPane.showMessageDialog(this, "No Se ha Modifico correctamente",
                                 "Error", JOptionPane.ERROR_MESSAGE);
            }       
            else
                if(cmbNombreProveedor.getSelectedItem()==null)
                    if(CNOrdenEntrada.insertar(dateFechaFactura.getDate(), Float.valueOf(txtTotal.getText()) ,txtFactura.getText(), listaLotes))
                    {
                        JOptionPane.showMessageDialog(this, "Se ha guardado correctamente", "Informacion", JOptionPane.INFORMATION_MESSAGE);
                        limpiar();
                    }
                    else
                         JOptionPane.showMessageDialog(this, "No Se ha guardado correctamente",
                                 "Error", JOptionPane.ERROR_MESSAGE);
                else
                {
                    ComboBox combo= (ComboBox)cmbNombreProveedor.getSelectedItem();
                    Proveedores prov= CNProveedor.buscarId(combo.getId()) ;
                    if(CNOrdenEntrada.insertar(dateFechaFactura.getDate(), Float.valueOf(txtTotal.getText()) ,txtFactura.getText(), listaLotes,prov.getIdProveedores()))
                    {
                        JOptionPane.showMessageDialog(this, "Se ha guardado correctamente", "Informacion", JOptionPane.INFORMATION_MESSAGE);
                        limpiar();
                    }
                    else
                         JOptionPane.showMessageDialog(this, "No Se ha guardado correctamente", "Error", JOptionPane.ERROR_MESSAGE);
                }
        }
        else
            JOptionPane.showMessageDialog(this, "No se han agregado Productos", "Informacion", JOptionPane.INFORMATION_MESSAGE);
        
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void limpiar()
    {
        cmbNombreProducto.removeAllItems();
        cmbNombreProveedor.removeAllItems();
        txtCantidad.setText("");
        txtDireccion.setText("");
        txtFactura.setText("");
        txtNombre.setText("");
        txtPrecio.setText("");
        txtTelefono.setText("");
        txtTotal.setText("");
        labGranTotal.setText("0.00");
        limpiarDetalle();
        ClearTable();   
        txtNombre.requestFocus(true);
    }
    
    private void ClearTable(){
        for (int i = 0; i < Tabla.getRowCount(); i++) {
            modelo.removeRow(i);
            i-=1;
        }
    }
    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        
        if(obs!=null)
            obs.actualizar();
        if(obsPadre != null)
            obsPadre.actualizar();
        this.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void cmbNombreProductoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cmbNombreProductoKeyTyped
        // TODO add your handling code here:
        JTextField textField = (JTextField)evt.getSource();
        String text = textField.getText();
        txtNombreProducto.setText(text);
    }//GEN-LAST:event_cmbNombreProductoKeyTyped

    private void cmbNombreProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbNombreProductoActionPerformed
        // TODO add your handling code here:
        if((cmbNombreProducto.getSelectedItem()!=null)&&(comboNombre==false))
        {
            ComboBox h = (ComboBox)cmbNombreProducto.getSelectedItem();
            Producto producto = CNProducto.buscarId(h.getId());
            txtDescripcion.setText(producto.getNombre() +" Medido en: " + producto.getUnidadDeMedidaidUnidadDeMedida().getNombre() );
            cargarUnidadMedidaConParametro(producto.getUnidadDeMedidaidUnidadDeMedida().getTipo());
        }
        
    }//GEN-LAST:event_cmbNombreProductoActionPerformed
    boolean comboNombre=false;
    private void txtNombreProductoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreProductoKeyTyped
        // TODO add your handling code here:
        limpiarProduct();
        if(txtNombreProducto.getText().length()>=2)
        {
            List<Producto> lista = CNProducto.buscarNombre(txtNombreProducto.getText());
            boolean x=true;
            for(Producto pro : lista)
            {
                x=false;
                cmbNombreProducto.addItem(new ComboBox(pro.getIdProducto(),pro.getNombre()));
            }
            comboNombre=false;
            if(x)
            {
                limpiarProduct();
                comboNombre=true;
            }
        }
        else
            limpiarProduct();
    }//GEN-LAST:event_txtNombreProductoKeyTyped

    private void chbFechaVencimientoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbFechaVencimientoActionPerformed
        // TODO add your handling code here:
        if(chbFechaVencimiento.isSelected())
        {
            dateVencimiento.setEnabled(true);
        }
        else 
        {
            dateVencimiento.setDate(null);
            dateVencimiento.setEnabled(false);
        }
    }//GEN-LAST:event_chbFechaVencimientoActionPerformed

    private void TablaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaMouseClicked
        /*/ TODO add your handling code here:
        int fila = Tabla.rowAtPoint(evt.getPoint());
        if (fila > -1)     
            txtNombre.setText(String.valueOf(Tabla.getValueAt(fila, 1)));
        else
            txtNombre.setText("hola");*/

    }//GEN-LAST:event_TablaMouseClicked

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        int fila = Tabla.getSelectedRow();
        if (fila > -1)   
        {
            Float precio = Float.valueOf(modelo.getValueAt(fila, 4).toString());
            Float totalCosto = Float.valueOf(labGranTotal.getText());
            totalCosto =totalCosto- precio;
            labGranTotal.setText(totalCosto.toString());
            modelo.removeRow(fila);
            if(listaEliminados!=null)
                listaEliminados.add(listaLotes.get(fila));
            listaLotes.remove(fila);
        }
        else
            JOptionPane.showMessageDialog(this, "Debe Seleccionar un  Elemento", "Error", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_btnEliminarActionPerformed
boolean comboProducto;
    private void cmbNombreProveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbNombreProveedorActionPerformed
        // TODO add your handling code here:
        if(cmbNombreProveedor.getSelectedItem()!=null)
        {
            ComboBox combo= (ComboBox)cmbNombreProveedor.getSelectedItem();
            Proveedores prov= CNProveedor.buscarId(combo.getId()) ;
            txtDireccion.setText(prov.getDireccion());
            txtTelefono.setText(prov.getTelefono());
        }
    }//GEN-LAST:event_cmbNombreProveedorActionPerformed

    private void cmbNombreProveedorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cmbNombreProveedorKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbNombreProveedorKeyTyped

    private void txtNombreProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNombreProductoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNombreProductoActionPerformed

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
        // TODO add your handling code here:
        limpiarProveedor();
        if(txtNombre.getText().length()>=2)
        {
            List<Proveedores> lista = CNProveedor.buscarNombre(txtNombre.getText());
            boolean x =true;
            for(Proveedores pro : lista)
            {
                x = false;
                cmbNombreProveedor.addItem(new ComboBox(pro.getIdProveedores(),pro.getNombre()));
            }
            comboProducto=false;
            if(x)
            {
                comboProducto=true;
                limpiarProveedor();
            }
        }
        else
            limpiarProveedor();
    }//GEN-LAST:event_txtNombreKeyTyped

    private void limpiarProveedor()
    {
        cmbNombreProveedor.removeAllItems();
        txtDireccion.setText("");
        txtTelefono.setText("");
    }
    
    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        // TODO add your handling code here:   
        if(chbFechaVencimiento.isEnabled())
        {
            if(dateVencimiento.getDate()!=null)
            {
                if(Calendar.getInstance().getTime().after( dateVencimiento.getDate()))
                {
                    JOptionPane.showMessageDialog(this, "Fecha incorrecta", "Error", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }
            }
        }
        if(cmbNombreProducto.getModel().getSize()!=-1 && comboNombre ==false && !"".equals(txtCantidad.getText()) && !"".equals(txtPrecio.getText()))
        {
             ComboBox combo = (ComboBox) cmbNombreProducto.getSelectedItem();
             ComboBox combo2 = (ComboBox) cmbUnidadMedida.getSelectedItem();
             Producto producto = CNProducto.buscarId(combo.getId());
             Unidaddemedida unidad = CNUnidadMedida.buscarId(combo2.getId());
             float cantidad = Float.valueOf(txtCantidad.getText());
             float precio=Float.valueOf(txtPrecio.getText());
             float precioUnitario = precio/cantidad;
            modelo.addRow(new Object[]{producto.getNombre(),producto.getDescripcion(),unidad.getNombre(),cantidad,precioUnitario, precio});
            Float granTotal = Float.valueOf(labGranTotal.getText());
            granTotal =granTotal+precio;
            labGranTotal.setText(granTotal.toString());
            Lotes lote = new Lotes();
            lote.setCantidad(Conversor.convertirProducto(producto.getUnidadDeMedidaidUnidadDeMedida(), unidad, cantidad));
            if(chbFechaVencimiento.isSelected())
                lote.setFechaDeVencimiento(dateVencimiento.getDate());
            lote.setPrecioUnitario(Conversor.convertirProducto(unidad,producto.getUnidadDeMedidaidUnidadDeMedida(),  precioUnitario));
            lote.setProductoidProducto(producto);
            Calendar fecha =  Calendar.getInstance();
            lote.setFechaDeIngreso(fecha.getTime());
            lote.setActivo(true);
            listaLotes.add(lote);
            txtNombreProducto.requestFocus(true);
            limpiarDetalle();
        }
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void limpiarDetalle()
    {
        cmbNombreProducto.removeAllItems();
        txtDescripcion.setText("");
        txtNombreProducto.setText("");
        txtPrecio.setText("");
        txtCantidad.setText("");
        chbFechaVencimiento.setSelected(false);
        dateVencimiento.setDate(null);
        dateVencimiento.setEnabled(false);
        txtNombreProducto.requestFocus(true);
    }
    
    private void txtCantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadKeyTyped
        // TODO add your handling code here:
        char c=evt.getKeyChar();  
        if((!Character.isDigit(c))&&(c != '.')) { 
              getToolkit().beep();                
              evt.consume(); 
          }
    }//GEN-LAST:event_txtCantidadKeyTyped

    private void txtPrecioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPrecioKeyTyped
        // TODO add your handling code here:
        char c=evt.getKeyChar();  
        if((!Character.isDigit(c))&&(c != '.')) { 
              getToolkit().beep();                
              evt.consume(); 
          }
    }//GEN-LAST:event_txtPrecioKeyTyped

    private void txtTotalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTotalKeyTyped
        // TODO add your handling code here:
        char c=evt.getKeyChar();  
        if((!Character.isDigit(c))&&(c != '.')) { 
              getToolkit().beep();                
              evt.consume(); 
          }
    }//GEN-LAST:event_txtTotalKeyTyped

    private void cmbUnidadMedidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbUnidadMedidaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbUnidadMedidaActionPerformed

    private void txtTotalFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTotalFocusGained
        // TODO add your handling code here:
        Object o = evt.getSource(); 
        if(o instanceof javax.swing.JTextField)
        { 
            javax.swing.JTextField txt = (javax.swing.JTextField) o; 
            txt.setSelectionStart(0); 
            txt.setSelectionEnd(txt.getText().length()); 
        }
    }//GEN-LAST:event_txtTotalFocusGained

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        IngresoProducto ing = new IngresoProducto(obs);
        MDI.getDesktopPane().add(ing);
        ing.show();
        this.Desactivar();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        IngresoProveedor ing = new IngresoProveedor(obs);
        MDI.getDesktopPane().add(ing);
        ing.show();
        this.Desactivar();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
        if(obs!=null)
            obs.actualizar();
        if(obsPadre != null)
            obsPadre.actualizar();
    }//GEN-LAST:event_formInternalFrameClosing

    private void limpiarProduct()
    {
        cmbNombreProducto.removeAllItems();
        txtDescripcion.setText("");
    }
    
     private void Desactivar()
    {
        for(Component x :this.jPanel2.getComponents())
            x.setEnabled(false);
        for(Component x : this.jLayeredPane1.getComponents())
            x.setEnabled(false);
        for(Component x : this.jLayeredPane2.getComponents())
            x.setEnabled(false);
        for(Component x : this.jLayeredPane3.getComponents())
            x.setEnabled(false);
    }
    private void Activar()
    {
        for(Component x :this.jPanel2.getComponents())
            x.setEnabled(true);
        for(Component x : this.jLayeredPane1.getComponents())
            x.setEnabled(true);
        for(Component x : this.jLayeredPane2.getComponents())
            x.setEnabled(true);
        for(Component x : this.jLayeredPane3.getComponents())
            x.setEnabled(true);
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable Tabla;
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JCheckBox chbFechaVencimiento;
    private javax.swing.JComboBox cmbNombreProducto;
    private javax.swing.JComboBox cmbNombreProveedor;
    private javax.swing.JComboBox cmbUnidadMedida;
    private com.toedter.calendar.JDateChooser dateFechaFactura;
    private com.toedter.calendar.JDateChooser dateVencimiento;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labGranTotal;
    private entidad.Ordenentrada ordenentrada1;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtFactura;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNombreProducto;
    private javax.swing.JTextField txtPrecio;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtTotal;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o, Object arg) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Activar();
    }
}
